﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SisEagle.View.Web.Base;
using System.Web.UI.HtmlControls;
using System.Web.Security;
using SisEagleVO;

namespace SisEagle.View.Web
{
    public partial class Default : System.Web.UI.MasterPage, IHierarchicalDataSource
    {

        #region OnInit / PageLoad
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
         
            if (! IsPostBack )
            {
              
                ControlaAcessoUsuario();
                ControlaPermissao();
            }
            inictialize();
        }

        private void inictialize()
        {
            LoginStatus1.LoggingOut += LoginStatus1_LoggingOut;
        }
      
        #endregion

        #region Internal

        internal void ControlaAcessoUsuario()
        {
            if (Session["Usuario"] == null)
            {
                Response.Redirect("~/Seguranca/Login.aspx");
            }


        }

        private void ControlaPermissao()
        {
            if (Session["Usuario"] is FuncionarioVO)
            {
                var permissao = (FuncionarioVO)Session["Usuario"];



                if (permissao.codPrevilegio == 1)
                {
                    SiteMapSouce.SiteMapProvider = "SiteVendedor"; 
                }
                if (permissao.codPrevilegio == 2)
                {
                    
                    SiteMapSouce.SiteMapProvider = "SiteAdministrador";
                }






            }
        }
        #endregion

        protected void LoginStatus1_LoggingOut(object sender, LoginCancelEventArgs e)
        {
            Session.Abandon();
            FormsAuthentication.SignOut();
        }




        public event EventHandler DataSourceChanged;

        public HierarchicalDataSourceView GetHierarchicalView(string viewPath)
        {
            throw new NotImplementedException();
        }
    }
}